package com.jamiexu.help.test;

import java.net.*;
import java.io.*;
import java.util.*;

public class Client
{
	public static void main(String[] args)
	{
		
		
		try
		{
			final ServerSocket sock = new ServerSocket(7553);
			new Thread(new Runnable(){

					@Override
					public void run()
					{
						// TODO: Implement this method

						try
						{
							Socket socket;
							while ((socket = sock.accept()) != null)
							{
								String d = SocketUtils.getData(socket);
								if(d!=null)
								System.out.println("收到服务器信息："+d);
								//System.out.println(SocketUtils.getData(socket));
								SocketUtils.sendData(socket,SocketUtils.getData(socket));
							}
							
							
						}
						catch (IOException e)
						{}
					}
				}).start();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		
		
		
		
		try
		{
			final Socket sock = new Socket("127.0.0.1", 7553);
			SocketUtils.sendData(sock,"我开了gfd fds fd fd sg fd ");
			
			new Thread(new Runnable(){

					@Override
					public void run()
					{
						// TODO: Implement this method
						while(true){
							String d = SocketUtils.getData(sock);
							if(d!=null)
							System.out.println("来自服务器："+d);
						}
					}
				}).start();
				
				
				Scanner sca = new Scanner(System.in);
				while(true){
					while(sca.hasNext()){
						SocketUtils.sendData(sock,sca.next());
					}
				}
			//System.out.println(SocketUtils.getData(sock));
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		
		
		
		
		
		
	}
}
